package study.springboot.mvc.support.runner;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerMapping;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * （1）用于指示 bean 包含在 SpringApplication 中时应运行的接口。可以定义多个
 * （2）在同一应用程序上下文中，可以使用有序接口或 @Order 注释对其进行排序
 */
@Slf4j
@Component
public class CustomApplicationRunner implements ApplicationRunner {

    @Autowired
    private List<HandlerMapping> handlerMappingLt;
    @Autowired
    private List<HandlerAdapter> handlerAdapterLt;
    @Autowired
    private List<HttpMessageConverter> converterLt;

    @PostConstruct
    public void init() {
        handlerMappingLt.forEach(e -> {
            log.info(">>>>>> {}", e.getClass().getName());
        });
        handlerAdapterLt.forEach(e -> {
            log.info("====== {}", e.getClass().getName());
        });
        converterLt.forEach(e -> {
            log.info(">>>>>> {}", e.getClass().getName());
        });
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info(">>>>>> ApplicationRunner");
    }
}
